package com.delivery.www.service.ServiceImpl;

import com.delivery.www.service.ComplaintService;
import com.delivery.www.constant.Constants;
import com.delivery.www.dao.ComplaintDao;
import com.delivery.www.dao.DaoImpl.ComplaintDaoImpl;
import com.delivery.www.po.Complaint;

import java.util.List;

/**
 * @author 12970
 */
public class ComplaintServiceImpl implements ComplaintService {
    private final ComplaintDao complaintDao = new ComplaintDaoImpl();

    @Override
    public String doComplaint(int userId, String content, String field, String store) {
        if (userId<=0||content==null){
            return "error";
        }else {
            int i;
            if (field == null) {
                i = complaintDao.doComplaint(userId, content, 2);
            } else {
                if (field.equals(Constants.STORE)) {
                    String s = "投诉店铺：" + store + " " + content;
                    i = complaintDao.doComplaint(userId, s, 1);

                } else {
                    i = complaintDao.doComplaint(userId, content, 2);
                }
            }
            if (i > 0) {
                return "ok";
            } else {
                return "error";
            }
        }
    }

    @Override
    public List<Complaint> getComplaint() {
        return complaintDao.getComplaint();
    }

    @Override
    public boolean deleteComplaint(int complaintId) {
        if (complaintId <= 0) {
            return false;
        } else {
            return complaintDao.deleteComplaint(complaintId) > 0;
        }
    }
}
